package com.project.class4_8.proxyMarke.dao.impl;

import java.net.CookieHandler;
import java.sql.*;

public class BaseDao {
    protected PreparedStatement ps;
    protected Connection con;
    protected ResultSet rs;

    /**
     * 获取连接
     * @return 连接对象
     */
    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection c= DriverManager.getConnection("jdbc:mysql://localhost:12345/me?characterEncoding=utf-8",
                    "root","lovo");
            return c;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void setConnection(Connection con){
        this.con=con;
    }

    public void updateData(String sql,Object...values){
        try {
            ps=con.prepareStatement(sql);
            for (int i=0;i<values.length;i++){
                ps.setObject(i+1,values[i]);
            }
            ps.executeLargeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
